package com.example.homelicaisystem.control;

import com.example.homelicaisystem.entity.DTO.InvestmentDTO;
import com.example.homelicaisystem.entity.DTO.InvestmentDetailDTO;
import com.example.homelicaisystem.entity.Investment;
import com.example.homelicaisystem.entity.InvestmentDetail;
import com.example.homelicaisystem.entity.ListWithCount;
import com.example.homelicaisystem.entity.SelectResult;
import com.example.homelicaisystem.services.InvestmentService;
import com.example.homelicaisystem.utils.HandleMoney;
import com.example.homelicaisystem.utils.Result;
import com.github.pagehelper.Page;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/investment")
@RestController
@Slf4j
public class InvestmentControl {
    private final InvestmentService investmentService;

    public InvestmentControl(InvestmentService investmentService) {
        this.investmentService = investmentService;
    }


    @PostMapping("/list")
    public Result<ListWithCount<Investment>> getList(@RequestBody InvestmentDTO data) {
        log.debug("收到请求list请求。参数:{}", data);
        Page<Investment> res = investmentService.getList(data);


        return Result.ok(new ListWithCount<>(res.getTotal(), res));
    }

    @PostMapping("selectType")
    public Result<List<SelectResult>> selectInvestmentType() {
        log.debug("收到selectInvestmentType请求");
        return Result.ok(investmentService.selectInvestmentType());
    }

    @PostMapping("selectInvestment")
    public Result<List<SelectResult>> selectInvestment(@RequestBody Investment data) {
        log.debug("收到selectInvestmentType请求");
        return Result.ok(investmentService.selectInvestment(data.getInvestmentType()));
    }

}
